package com.dreamwhale.machinery.config;

import com.dreamwhale.machinery.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class JWTConfigurer implements WebMvcConfigurer {

    @Value("${static.file.path}")
    String imgPath;

    @Bean
    public JwtUtils jwtUtils() {
        return new JwtUtils();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/**");
        registry.addResourceHandler("/img/**").addResourceLocations("file:" + imgPath);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        JWTInterceptor jwtInterceptor = new JWTInterceptor(jwtUtils());
        InterceptorRegistration loginRegistry = registry.addInterceptor(jwtInterceptor);
        loginRegistry.addPathPatterns("/user/insertMachineSells");
        loginRegistry.addPathPatterns("/user/insertLeases");
        loginRegistry.addPathPatterns("/user/insertDriverInfos");
        loginRegistry.addPathPatterns("/user/insertDriverWorkInfos");
        loginRegistry.addPathPatterns("/user/insertMachineBuys");
        loginRegistry.addPathPatterns("/user/insertTransportCompanyInfos");
        loginRegistry.addPathPatterns("/user/insertProjectSeeks");
        loginRegistry.addPathPatterns("/user/insertTransportInfos");
        loginRegistry.addPathPatterns("/user/insertUserShops");
        //loginRegistry.addPathPatterns("/user/selectYxStoreProductByMerId");
        loginRegistry.addPathPatterns("/user/insertUserShopsCollect");
        loginRegistry.addPathPatterns("/user/selectMyMeassages");
        loginRegistry.addPathPatterns("/user/selectMyMeassagesbyType");
        loginRegistry.addPathPatterns("/user/updateMyPassWords");
        loginRegistry.addPathPatterns("/user/insertYxUserAddress");
        loginRegistry.addPathPatterns("/user/selectYxUserAddressByUserId");
        loginRegistry.addPathPatterns("/user/updateYxUserAddress");
//        loginRegistry.addPathPatterns("/user/selectDriverInfoBytypeId");
        loginRegistry.addPathPatterns("/user/selectUserShopCollects");
        loginRegistry.addPathPatterns("/user/deleteUserShopCollects");
//        loginRegistry.addPathPatterns("/user/selectVipArticleCollects");
        loginRegistry.addPathPatterns("/user/deleteVipArticleCollects");
//        loginRegistry.addPathPatterns("/pay/payOrderCarts");
        loginRegistry.addPathPatterns("/user/selectYxUserByUserId");
        loginRegistry.addPathPatterns("/pay/payMiniWeChatTrolleyOrders");
        loginRegistry.addPathPatterns("/user/updateYxUserByUserId");
        loginRegistry.addPathPatterns("/user/insertYxUserWithdraws");
        loginRegistry.addPathPatterns("/user/selectYxUserBillsByUserId");
        loginRegistry.addPathPatterns("/user/insertMachinists");
        loginRegistry.addPathPatterns("/user/selectVipArticlesById");
        loginRegistry.addPathPatterns("/user/insertVipArticles");
        loginRegistry.addPathPatterns("/user/insertYxUserFeedBacks");
        loginRegistry.addPathPatterns("/user/insertInfoCollect");
        loginRegistry.addPathPatterns("/user/delInfoCollects");
//        loginRegistry.addPathPatterns("/user/selectInfoCollect");
        loginRegistry.addPathPatterns("/yxUserBill/transactionRecords");
        loginRegistry.addPathPatterns("/yxUser/userApply");
        loginRegistry.addPathPatterns("/yxUser/personalInformation");
        loginRegistry.addPathPatterns("/yxUser/inquiryOrder");
        loginRegistry.addPathPatterns("/yxUser/orderInfo");
        loginRegistry.addPathPatterns("/yxUser/inquiryConsultingCollection");
        loginRegistry.addPathPatterns("/yxStoreCart/**");
        loginRegistry.addPathPatterns("/yxStoreCart/**");
        loginRegistry.addPathPatterns("/vipUserInfo/buyVip");
        loginRegistry.addPathPatterns("/pay/payMiniWeChatOrder");
        loginRegistry.addPathPatterns("/pay/payMiniWeChatTrolleyOrder");
        loginRegistry.addPathPatterns("/pay/payMiniWeChatOfficial");

//        loginRegistry.excludePathPatterns("/yxUser/login");
//        loginRegistry.excludePathPatterns("/yxUser/register");
//        loginRegistry.excludePathPatterns("/yxUser/verificationCode");
//        loginRegistry.excludePathPatterns("/weChatPay/notify");
//        loginRegistry.excludePathPatterns("/ali/notify");
//        loginRegistry.excludePathPatterns("/projectSeek/getIndexInfo");
    }

}
